package java_thinking.unit_14;

import java_thinking.unit_14.VO.SearchConditionVO;
import java_thinking.unit_14.VO.ShareVO;

import java.util.*;

/**
 * @Description :
 * @author: cww
 * @DateTime: 2019/3/29 20:34
 */

public class Demo {
    public void getDataInterface(){
        /**
         * 假设这里通过查询得到了一个list
         */
        List<SearchConditionVO> searchConditionVOS = new ArrayList<>();
        /**
         * 这个list需要做一些加工，使用内部类的方式
         */
        new FilterTaskName<SearchConditionVO>().filter(searchConditionVOS);
    }

    /**
     * 要求：继承于ShareVO的子类中的taskName相同的，在其taskName后面加上对应的团队名称-teamName
     * @param <T>
     */
    class FilterTaskName<T extends ShareVO> extends HashMap<String,Integer> {
        void filter(List<T> shareVOList){
            Set<String> taskNameList = new HashSet<>();
            for (ShareVO shareVO:shareVOList){
                Integer integer = get(shareVO.getTaskName());
                if (integer == null){
                    put(shareVO.getTaskName(),1);
                } else {
                    put(shareVO.getTaskName(),integer+1);
                    if (get(shareVO.getTaskName())>1){
                        taskNameList.add(shareVO.getTaskName());
                    }
                }
            }
            for (String taskName : taskNameList){
                for (ShareVO shareVO : shareVOList){
                    if (taskName.equals(shareVO.getTaskName())){
                        shareVO.setTaskName(shareVO.getTaskName()+"-"+shareVO.getTeamName());
                    }
                }
            }
        }
    }
}
